<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

		<div id="container">
			<div id="content" role="main">
				<div id="newsletter-slider">
					<div class="slides_container">
					<?php
					/* Run the loop to output the page.
					 * If you want to overload this in a child theme then include a file
					 * called loop-page.php and that will be used instead.
					 */
					 
					
					
					$posts = wmp_get_popular( array( 'limit' => 5, 'post_type' => 'post', 'range' => 'all_time' ) );
					global $post;
					if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
						setup_postdata( $post );
						$large_image_url =  get_bloginfo('stylesheet_directory') . "/images/home-default-image.png";
						if ( has_post_thumbnail()) {
							$large_image_urls = wp_get_attachment_image_src( get_post_thumbnail_id(), 'home-thumb');
							$large_image_url = $large_image_urls[0];
						}
						
						$the_tags = get_the_tags();
							
						if(($the_tags) > 0) {
						  $the_tag = array_shift(array_values($the_tags));
						  $the_tag = $the_tag->name;
						} else if((get_the_category()) > 0){
						  $the_cats = get_the_category();
						  $the_cat = array_shift(array_values($the_cats));
						  
						  $the_tag = $the_cat->name;
						} else $the_tag = 'Other';

						?>
						<div id="post-<?php echo $post->ID?>">
							<a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>">
								<img src="<?php echo $large_image_url; ?>" alt="" class="home-thumb" />
							</a>
							<p><?php the_title(); ?></p>
							<div class="ribbon-wrapper-green"><div class="ribbon-green"><?php echo substr($the_tag, 0 , 10);  ?></div></div>
							<a class="read-more-btn" href="<?php the_permalink(); ?>">
							<img src="<?php bloginfo('stylesheet_directory') ?>/images/plus-btn.gif" alt="Read more ..."/>
						</a>
						</div>
						
						<?php
					endforeach; endif;
					?>
					</div>
				</div>

			</div><!-- #content -->
			<div class="subscribe opacity">
				<p><span>Be ready - Subscribe ! </span><a href="#" class="eModal eModal-1">&nbsp;</a></p>
			</div>			
		</div><!-- #container -->
		<script type="text/javascript">
		(function($){
			jQuery('#newsletter-slider').slides({
				generatePagination : false,
				preload: true,
				generateNextPrev  : true,
				// start: posts_index.current_idx,
				animationComplete: function(current){
					// console.info("animationComplete");
					// jsonGetPostContent(current, $("#slides"));
				}
				
			});
		})(jQuery);
		</script>
<?php get_footer(); ?>
